package com.kyub.spring.gears.model;

import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

/**
 */
public class PojoDescriptor extends AbstractPojoDescriptor{

    private Class pojoClass;

    private String name;

    private String idProperty;


    public PojoDescriptor(AbstractPojoDescriptor parent) {

        this.setAllowedRoles(parent.getAllowedRoles());
        this.setEditableRoles(parent.getEditableRoles());
        this.setInsertableRoles(parent.getInsertableRoles());
        this.setDeletableRoles(parent.getDeletableRoles());
        this.setDeletable(parent.getDeletable());
        this.setInsertable(parent.getInsertable());
        this.setEditable(parent.getEditable());


    }

    public PojoDescriptor() {

    }
    
    private List<PropertyDescriptor> properties = new ArrayList();


    public Class getPojoClass() {
        return pojoClass;
    }

    public void setPojoClass(Class pojoClass) {
        this.pojoClass = pojoClass;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIdProperty() {
        return idProperty;
    }

    public void setIdProperty(String idProperty) {
        this.idProperty = idProperty;
    }

    public List<PropertyDescriptor> getProperties() {
        return properties;
    }

    public void setProperties(List<PropertyDescriptor> properties) {
        this.properties = properties;
    }



    public PropertyDescriptor getProperty(String param){
        Iterator<PropertyDescriptor> i = properties.iterator();
        while (i.hasNext()) {
            PropertyDescriptor propertyDescriptor = i.next();
            if(propertyDescriptor.getName().equals(param))
                return propertyDescriptor;
        }
        return null;
    }

    public PropertyDescriptor getFormFiled(String param){
        Iterator<PropertyDescriptor> i = getFormFields().iterator();
        while (i.hasNext()) {
            PropertyDescriptor propertyDescriptor = i.next();
            if(propertyDescriptor.getName().equals(param))
                return propertyDescriptor;
        }
        return null;
    }


}
